package org.eredlab.g4.lz.service.impl;

import java.util.List;

import org.eredlab.g4.arm.util.idgenerator.IDHelper;
import org.eredlab.g4.bmf.base.BizServiceImpl;
import org.eredlab.g4.ccl.datastructure.Dto;
import org.eredlab.g4.lz.service.OrderService;

/**
 * 订单操作 数据 实现类
 * @author kay
 * @date 2013-3-24
 */
public class OrderServiceImpl extends BizServiceImpl implements OrderService {

	@Override
	public Dto insertOrder(Dto dto,List<Dto> lst) {
		String orderNo = IDHelper.getGoodId("DD", 0);
		double totalp = 0;
		double totals = 0;
		for(Dto ddto : lst){
			ddto.put("ordernos", orderNo);
			ddto.put("detailno", IDHelper.getGoodId("DE", 0));
			totalp += Double.parseDouble(ddto.getAsString("dj")) * ddto.getAsInteger("ordernum");
			totals += Double.parseDouble(ddto.getAsString("dj")) * ddto.getAsInteger("ordernum") * Double.parseDouble(ddto.getAsString("zk"));
			g4Dao.insert("lz.detail_insert_1", ddto);
		}
		dto.put("ordernos", orderNo);
		dto.put("totalp", totalp);
		dto.put("totals", totals);
		g4Dao.insert("lz.order_insert_1", dto);
		return dto;
	}

	@Override
	public Dto updateOrder(Dto dto,List<Dto> lst,String delids) {
		String orderno = dto.getAsString("ordernos");
		dto.put("delids", delids);
		g4Dao.update("lz.detail_delete_1", dto);
		for(Dto ddto : lst){
			if("自动生成".equalsIgnoreCase(ddto.getAsString("detailno"))){
				ddto.put("ordernos", orderno);
				ddto.put("detailno", IDHelper.getGoodId("DE", 0));
				g4Dao.insert("lz.detail_insert_1", ddto);
			}else{
				g4Dao.update("lz.detail_updete_1", ddto);
			}
		}
		g4Dao.update("lz.order_update_1", dto);
		return null;
	}

	@Override
	public List queryOrder(Dto Dto) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public int deleteOrder(Dto dto) {
		return g4Dao.update("lz.delete_update_1", dto);
	}

	@Override
	public int auditOrderBySchool(Dto dto) {
		return g4Dao.update("lz.order_update_school", dto);
	}

	
	@Override
	public int auitOrderByBoard(Dto dto,List<Dto> dtolst) {
		
		//循环插入期初入库表
		for(Dto dtos:dtolst){
			g4Dao.insert("lz.perstock_insert_1", dtos);
		}
		return g4Dao.update("lz.order_update_board", dto);
	}

	@Override
	public int auitOrderByReject(Dto dto) {
		return g4Dao.update("lz.order_update_reject", dto);
	}

}
